# -*- coding: utf-8 -*-
# @Time    : 2022/10/23 15:13
# @Author  : 限量老
from django import forms
from django.forms import Form,ModelForm

class BootStrap:
    bootstrap_exclude_fields =[]  # 设定不应用样式的 项

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 循环找到所有的插件,添加了class='form-control,传到页面中去
        for name, field in self.fields.items():

            # 设定不应用样式的 项
            if name in self.bootstrap_exclude_fields:
                continue

            #字段中有属性,保留原来的属性,没有属性,才增加
            if field.widget.attrs:
                field.widget.attrs['class']='form-control'
                field.widget.attrs['placeholder']=field.label
            else:
                field.widget.attrs = {'class': 'form-control', 'placeholder': field.label}

class BootStrapModelForm(BootStrap,ModelForm):#继承ModelForm
    pass

class BootStrapForm(BootStrap,Form):#继承Form
    pass
























